$(document).ready(function(){

    $("#tri").change(function(){
        top.location=$(this).val();
    });

    $("#form_search").submit(function() {
        var type = $("#form_type").val().toLowerCase();
        $("#form_search").attr("action", URL_PATH + "recherche/" + type + "/" + $("#rech2").val().toLowerCase()+"/");
    });

    $("#rech2").focus(function() {
        if($("#rech2").val().indexOf("Recherchez") != -1) { $("#rech2").val(""); }
    });
    $("#button_rech").click(function() {
        $("#form_search").submit();
    });

    /* Autocompletion */
    if($("#form_type").val().toLowerCase() == "boutique") {
        $("#rech2").autocomplete(AJAX_PATH + "complete_search.ajax.php", { minChars:2, matchSubset:1, matchContains:1, cacheLength:10, onItemSelect:selectItem, formatItem:formatItem, selectOnly:1 });
    }
});

function selectItem(li) {
    $("#form_search").submit();
}
function formatItem(row) {
	return "<div class='img'><img src='" + URL_PATH + row[1] + "' alt='' /></div><div class='label'>" + row[0] + "</div>";
}
